home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8836 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem Negating an Unsigned Char
  5. Date: 04 Mar 1996 15:19:21 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Mar4081921@qcd.lanl.gov>
  8. References: <Dnnros.Lq.0.-s@hkusuc.hku.hk> <4he27sINNdel@keats.ugrad.cs.ubc.ca>
  9.     <DnqMyr.4pF@cwi.nl>
  10. NNTP-Posting-Host: qcd.lanl.gov
  11. Mime-Version: 1.0
  12. Content-Type: text
  13. In-reply-to: dik@cwi.nl's message of Mon, 4 Mar 1996 10:11:15 GMT
  14.  
  15. In article <DnqMyr.4pF@cwi.nl>
  16. dik@cwi.nl (Dik T. Winter) writes:
  17.  
  18. <snip>
  19. DTW:  > >unsigned char a=0x11;
  20. DTW:  > >unsigned char b=0xEE;
  21. <snip>
  22. DTW:  > 
  23. DTW:  > To make it portable, you must manually mask for the lower eight bits:
  24. DTW:  > 
  25. DTW:  >     if (a == (~b & 0xff))
  26. DTW: 
  27. DTW: And how would this work on machines with other than eight bit chars?
  28. DTW: Casting to unsigned char will work regardless the number of bits
  29. in a char. 
  30.  
  31. I guess what the poster meant was that given the values of a and b,
  32. except on machines with 8 bit chars, (unsigned char)~b will not
  33. compare equal to a: whereas, ~b & 0xff will irrespective of the size
  34. of types. This happens to be true.
  35.  
  36. Cheers
  37. Tanmoy
  38. --
  39. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  40. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  41. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  42. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  43. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  44. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  45.